package com.test.application.loadFile.loadTXT.demo1;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 描述: 读取txt文件
 * 作者: yanruizhi
 * 时间: 2024/9/19 17:03
 */
@Slf4j
@Service
public class LoadTXT {

    public void load() throws URISyntaxException {
        URL resource = this.getClass().getClassLoader().getResource("file/address.txt");
        Path path = null;
        if (resource != null) {
            path = Paths.get(resource.toURI());
            log.info("path:{}", path);
        }
        try (BufferedReader br = new BufferedReader(new FileReader(path.toString()))) {
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}
